﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Aioms.Common;
using Aioms.Dtos;
using Aioms.Models;
using Furion;
using Furion.DataEncryption;
using Furion.DynamicApiController;
using Furion.UnifyResult;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Core.Extension;
using Magicodes.ExporterAndImporter.Excel;
using Masuit.Tools;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OfficeOpenXml;
using SqlSugar;
using StackExchange.Profiling.Internal;

namespace Aioms.Controllers
{
    /// <summary>
    /// 报修
    /// </summary>
    [DynamicApiController]
    public class NoticeRepairController
    {
        private readonly IWebHostEnvironment _env;
        private readonly ISqlSugarClient db; // 核心对象：拥有完整的SqlSugar全部功能
        public NoticeRepairController(IWebHostEnvironment env, ISqlSugarClient sqlSugarClient)
        {
            this.db = sqlSugarClient;
        }

        /// <summary>
        /// 报修列表
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="content"></param>
        /// <param name="status"></param>
        /// <param name="sbepid"></param>
        /// <param name="nextepid"></param>
        /// <param name="lastepid"></param>
        /// <param name="cyplepid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostList([FromForm] long eid, [FromForm] string content, [FromForm] int status, [FromForm] long sbepid, [FromForm] long nextepid, [FromForm] long lastepid, [FromForm] long cyplepid, [FromForm] int pageIndex = 1, [FromForm] int pageSize = 10)
        {
            // SQL：SELECT *, chuli_result->'$[*].id' FROM `notice_repair` where eid = 11 and json_contains(chuli_result, json_object('id', 46, 'shstatus', '')) and status != 4
            RefAsync<int> total = 0;
            List<NoticeRepair> noticeRepairs = await db.Queryable<NoticeRepair>()
                //.Mapper(np => np.Device, np => np.Dvid, np => np.Device.Id)
                //.Mapper(np => np.Device.Area = db.Queryable<Area>().Where(a => a.Id == np.Device.Aeid).Single())
                .Where(np => np.Eid == eid && np.IsDel == 0)
                .WhereIF(!string.IsNullOrEmpty(content), np => np.RpNumber.Contains(content) || np.Dvname.Contains(content) || np.Dvnumber.Contains(content) || np.Specification.Contains(content))
                .WhereIF(status != 0, np => np.Status == status)
                .WhereIF(sbepid != 0, np => np.Sbepid == sbepid)
                .WhereIF(nextepid != 0, $"json_contains(chuli_result, json_object('Id', {nextepid}, 'ShStauts', '', 'IsActive', true)) and status != 4 and status != 3")
                .WhereIF(lastepid != 0, $"json_contains(chuli_result, json_object('Id', {lastepid}, 'ShStauts', '2'))")
                .WhereIF(cyplepid != 0, $"json_contains(chuli_result, json_object('Id', {cyplepid}, 'IsActive', true)) and (status = 3 or status = 4)")
                .OrderBy(np => np.Id, OrderByType.Desc)
                .ToPageListAsync(pageIndex, pageSize, total);

            UnifyContext.Fill(new { Total = total.Value });
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = noticeRepairs,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// PC端-安卓端-新增
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="noticerepair"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostSave([FromForm] long eid, [FromForm] NoticeRepair noticerepair) {
            // 生成审批流程
            string spepids = await db.Queryable<Enterprise>().Where(e => e.Id == eid).Select(e => e.ExamineEpid).SingleAsync();
            List<Employee> employees = await db.Queryable<Employee>().Where($"FIND_IN_SET(id, '{spepids}')").Where(ep => ep.DefaultEid == eid).OrderBy($"FIND_IN_SET(id, '{spepids}')").ToListAsync();
            List<ShenPiPersonInfo> shenpiflow = new();
            shenpiflow.Add(new ShenPiPersonInfo { Id = noticerepair.Sbepid, Realname = noticerepair.SbepRealname, Role = "报修人", IsActive = true, Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ShStauts = "1", Comments = new() });
            foreach (var employee in employees)
            {
                if (employees.IndexOf(employee) == 0)
                {
                    shenpiflow.Add(new ShenPiPersonInfo { Id = employee.Id, Realname = employee.Realname, Role = "审批人", IsActive = true, Time = "", ShStauts = "", Comments = new() });
                }
                else {
                    shenpiflow.Add(new ShenPiPersonInfo { Id = employee.Id, Realname = employee.Realname, Role = "审批人", IsActive = false, Time = "", ShStauts = "", Comments = new() });
                }
            }
            //noticerepair.ChuliResult = shenpiflow.ToJson();
            noticerepair.ChuliResult = shenpiflow;
            noticerepair.ChuliStatus = "报修待审核";
            noticerepair.Status = 1;

            // 插入数据库
            long lastnpid = await db.Insertable<NoticeRepair>(noticerepair).ExecuteReturnIdentityAsync();

            #region 发送消息到第一个审批人
            // 找到该企业审批人
            await db.Insertable<Message>(new Message { Eid = eid, Name = noticerepair.Dvname, Qian = "发现故障，", Hou = "请及时处理！", Epid = employees.First().Id, Source = "报修", RefId = lastnpid, Type = "故障", Isread = 0 }).ExecuteCommandAsync();
            #endregion
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// PC端-安卓端-新增
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="noticerepair"></param>
        /// <returns></returns>
        /*public async Task<IActionResult> PostSave([FromForm] long eid, [FromForm] NoticeRepair noticerepair)
        {
            // 设置当前企业第一个审批人为下一个审批人
            string examinepid = await db.Queryable<Enterprise>().Where(e => e.Id == eid).Select(e => e.ExamineEpid).SingleAsync();
            if (!string.IsNullOrEmpty(examinepid))
            {
                string[] examinepidarr = examinepid.Split(",");
                noticerepair.Nextepid = long.Parse(examinepidarr.First());
            }

            long lastnpid = await db.Insertable<NoticeRepair>(noticerepair).ExecuteReturnIdentityAsync();

            #region 发送消息到第一个审批人
            // 找到该企业审批人
            string examineepids = await db.Queryable<Enterprise>().Where(e => e.Id == eid).Select(e => e.ExamineEpid).SingleAsync();
            if (!string.IsNullOrEmpty(examineepids))
            {
                long epid = long.Parse(examineepids.Split(",", StringSplitOptions.RemoveEmptyEntries)[0]);
                await db.Insertable<Message>(new Message { Eid = eid, Name = noticerepair.Dvname, Qian = "发现故障，", Hou = "请及时处理！", Epid = epid, Source = "报修", RefId = lastnpid, Type = "故障", Isread = 0 }).ExecuteCommandAsync();
            }
            #endregion
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }*/

        /// <summary>
        /// 修改接口
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="noticerepair"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostUpdate([FromForm] long eid, [FromForm] NoticeRepair noticerepair)
        {
            await db.Updateable<NoticeRepair>(noticerepair)
                .UpdateColumns(np => new { np.RpNumber, np.AeId, np.AeName, np.Dvid, np.Dvname, np.Dvnumber, np.Specification, np.DvPosition, np.DvFullAddress, np.Manufacturer, np.Position, np.Level, np.TroubleTime, np.IsHalt, np.Description, np.ImgUrl, np.VideoUrl, np.VoiceUrl, np.Sbepid, np.SbepRealname })
                .ExecuteCommandAsync();
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 删除接口
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostDelete([FromForm] long eid, [FromForm] long id)
        {
            await db.Updateable<NoticeRepair>(new NoticeRepair { IsDel = 1 }).UpdateColumns(nr => new { nr.IsDel }).Where(np => np.Eid == eid && np.Id == id).ExecuteCommandAsync();
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 安卓端-今日报修
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="sbepid"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostJinribaoxiu([FromForm] long eid, [FromForm] long sbepid)
        {
            int jrwc_total = await db.Queryable<NoticeRepair>()
                .Where(np => np.Eid == eid && np.Sbepid == sbepid)
                .Where(np => np.Created.Date == DateTime.Now.Date)
                .CountAsync();

            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = jrwc_total,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="id"></param>
        /// <param name="chuliresult"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostShenhe([FromForm] long eid, [FromForm] long id, [FromForm] string chulistatus, [FromForm] string chuliresult) {
            Dictionary<string, int> status = new() { { "报修待审核", 1 }, { "报修审核中", 2 }, { "报修已同意", 3 }, { "报修已拒绝", 4 }, { "维修中", 5 }, { "维修已完成", 6 } };

            //await db.Updateable<NoticeRepair>(new NoticeRepair { ChuliResult = JsonConvert.DeserializeObject<List<ShenPiPersonInfo>>(chuliresult), ChuliStatus = chulistatus, Status = status[chulistatus] })
            //    .UpdateColumns(np => new { np.ChuliResult, np.ChuliStatus, np.Status})
            //    .Where(np => np.Eid == eid && np.Id == id)
            //    .ExecuteCommandAsync();

            await db.Updateable<NoticeRepair>()
                .SetColumns(np => new NoticeRepair { ChuliResult = JsonConvert.DeserializeObject<List<ShenPiPersonInfo>>(chuliresult), ChuliStatus = chulistatus, Status = status[chulistatus] })
                .Where(np => np.Eid == eid && np.Id == id)
                .ExecuteCommandAsync();

            NoticeRepair noticerepair = await db.Queryable<NoticeRepair>().Where(np => np.Eid == eid && np.Id == id).SingleAsync();

            // 加入工单
            NrWorkOrder nrworkorder = await db.Queryable<NrWorkOrder>().Where(wo => wo.Eid == eid && wo.NpId == id).SingleAsync();
            if (nrworkorder == null && chulistatus.Equals("报修已同意"))
            {
                // 改变该设备状态
                await db.Updateable<Device>().SetColumns(dv => dv.Status == "故障").Where(dv => dv.Eid == eid && dv.Id == noticerepair.Dvid).ExecuteCommandAsync();
                //await db.Insertable<WorkOrder>(new WorkOrder { Eid = eid, Number = DateTime.Now.ToString("yyyyMMddHHmmss"), Source = "报修", RefId = id, Name = noticerepair.Position, Type = "维修工单", Extra = "", BeginTime = DateTime.MinValue, EndTime = DateTime.MinValue, ManHour = -1, SjBeginTime = DateTime.MinValue, SjEndTime = DateTime.MinValue, SjManHour = 0, Epids = "", Imageurl = noticerepair.ImgUrl, Videourl = noticerepair.VideoUrl, Voiceurl = noticerepair.VoiceUrl, Status = "待接单", Progress = "" }).ExecuteCommandAsync();
                await db.Insertable<NrWorkOrder>(new NrWorkOrder { Id = 0, Eid = eid, NpId = noticerepair.Id, Level = noticerepair.Level, Number = DateTime.Now.ToString("yyyyMMddHHmmss"), Name = noticerepair.Position, Dvid = noticerepair.Dvid, Dvname = noticerepair.Dvname, ManHour = "", SjResult = "", SjProcedure = "", BeginTime = DateTime.MinValue, EndTime = DateTime.MinValue, SjBeginTime = DateTime.MinValue, SjEndTime = DateTime.MinValue, SjManHour = "", Epids = "", Status = "待接单", SjWxEpId = 0, SjWxEpRealname = "" }).ExecuteCommandAsync();
            }

            #region 发送给报修人审核消息
            if (chulistatus.Equals("报修已同意") || chulistatus.Equals("报修已拒绝"))
            {
                await db.Insertable<Message>(new Message { Eid = eid, Name = noticerepair.RpNumber, Qian = "您的报修", Hou = $"审批" + (chulistatus.Equals("报修已同意") ? "已同意" : "被拒绝") + "！", Epid = noticerepair.Sbepid, Source = "报修", RefId = id, Type = "审批", Isread = 0 }).ExecuteCommandAsync();
            }
            #endregion

            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="id"></param>
        /// <param name="chuliresult"></param>
        /// <returns></returns>
        /*public async Task<IActionResult> PostShenhe([FromForm] long eid, [FromForm] long id, [FromForm] long lastepid, [FromForm] string chulistatus, [FromForm] string chuliresult)
        {
            Dictionary<string, int> status = new() { { "报修待审核", 1 }, { "报修审核中", 2 }, { "报修已同意", 3 }, { "报修已拒绝", 4 }, { "维修中", 5 }, { "维修已完成", 6 } };

            // 找到下一个审批人
            long nextepid = 0;
            JArray chuliresults = JArray.Parse(chuliresult);
            foreach (var clrs in chuliresults)
            {
                JObject clr = JObject.FromObject(clrs);
                if (clr.Property("shstatus") != null && string.IsNullOrEmpty(clr["shstatus"].ToString()))
                {
                    nextepid = Convert.ToInt32(clr["id"]);
                    break;
                }
            }

            await db.Updateable<NoticeRepair>()
                .SetColumns(np => new NoticeRepair { Lastepid = lastepid, Nextepid = nextepid, ChuliResult = chuliresult, ChuliStatus = chulistatus, Status = status[chulistatus] })
                .Where(np => np.Eid == eid && np.Id == id)
                .ExecuteCommandAsync();

            NoticeRepair noticerepair = await db.Queryable<NoticeRepair>().Where(np => np.Eid == eid && np.Id == id).SingleAsync();

            // 加入工单
            WorkOrder workorder = await db.Queryable<WorkOrder>().Where(wo => wo.Eid == eid && wo.Source == "报修" && wo.RefId == id).SingleAsync();
            if (workorder == null && chulistatus.Equals("报修已同意"))
            {
                // 改变该设备状态
                await db.Updateable<Device>().SetColumns(dv => dv.Status == "故障").Where(dv => dv.Eid == eid && dv.Id == noticerepair.Dvid).ExecuteCommandAsync();
                await db.Insertable<WorkOrder>(new WorkOrder { Eid = eid, Number = DateTime.Now.ToString("yyyyMMddHHmmss"), Source = "报修", RefId = id, Name = noticerepair.Position, Type = "维修工单", Extra = "", BeginTime = DateTime.MinValue, EndTime = DateTime.MinValue, ManHour = -1, SjBeginTime = DateTime.MinValue, SjEndTime = DateTime.MinValue, SjManHour = 0, Epids = "", Imageurl = noticerepair.ImgUrl, Videourl = noticerepair.VideoUrl, Voiceurl = noticerepair.VoiceUrl, Status = "待接单", Progress = "" }).ExecuteCommandAsync();
            }

            #region 发送给报修人审核消息
            if (chulistatus.Equals("报修已同意") || chulistatus.Equals("报修已拒绝")) {
                await db.Insertable<Message>(new Message { Eid = eid, Name = noticerepair.RpNumber, Qian = "您的报修", Hou = $"审批" + (chulistatus.Equals("报修已同意") ? "已同意" : "被拒绝") + "！", Epid = noticerepair.Sbepid, Source = "报修", RefId = id, Type = "审批", Isread = 0 }).ExecuteCommandAsync();
            }
            #endregion

            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }*/

        /// <summary>
        /// 返回审批结果
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="id"></param>
        /// <param name="chuliresult"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostShenheresult([FromForm] long eid, [FromForm] long id)
        {
            //string chuliresult = await db.Queryable<NoticeRepair>().Where(np => np.Eid == eid && np.Id == id).Select(np => np.ChuliResult).SingleAsync();
            NoticeRepair noticeRepair = await db.Queryable<NoticeRepair>().Where(np => np.Eid == eid && np.Id == id).SingleAsync();

            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                //Data = string.IsNullOrEmpty(chuliresult) ? null : JArray.Parse(chuliresult),
                Data = noticeRepair.ChuliResult,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 报修详情
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostShow([FromForm] long eid, [FromForm] long id)
        {
            NoticeRepair noticerepair = await db.Queryable<NoticeRepair>().Where(np => np.Eid == eid && np.Id == id).SingleAsync();
            //Device device = null;
            //if (noticerepair != null)
            //{
            //    device = await db.Queryable<Device>().Where(dv => dv.Id == noticerepair.Dvid).SingleAsync();
            //    device.Area = await db.Queryable<Area>().Where(a => a.Id == device.Aeid).SingleAsync();
            //}
            //UnifyContext.Fill(new { Device = device });
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = noticerepair,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 查看进度
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostChakanjindu([FromForm] long eid, [FromForm] long id)
        {
            NrWorkOrder nrWorkOrder = await db.Queryable<NrWorkOrder>().Where(nrwo => nrwo.Eid == eid && nrwo.NpId == id).SingleAsync();

            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = nrWorkOrder,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 下载模板
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> PostDownloadexceltemplate()
        {
            IExcelExporter exporter = new ExcelExporter();
            var filePath = @"wwwroot/download/baoxiu/报修模板.xlsx";
            var arr = new[] { "报修名称", "报修型号", "规格" };
            var sheetName = "报修";
            var result = await exporter.ExportHeaderAsByteArray(arr, sheetName);
            result.ToExcelExportFileInfo(filePath);
            JObject data = new();
            data.Add("url", $"http://{App.HttpContext.Request.Host.Value}/download/baoxiu/报修模板.xlsx");
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = data,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> PostExportexcel([FromForm] long eid)
        {
            IExporter exporter = new ExcelExporter();
            List<NoticeRepair> noticerepairs = await db.Queryable<NoticeRepair>().Where(np => np.Eid == eid).ToListAsync();
            foreach (var noticerepair in noticerepairs)
            {
                Dictionary<int, string> ishaltdic = new() { { 1, "是" }, { 2, "否" } };
                Dictionary<int, string> leveldic = new() { { 1, "轻微" }, { 2, "一般" }, { 3, "紧急" } };
                noticerepair.IsHaltName = ishaltdic[noticerepair.IsHalt];
                noticerepair.LevelName = leveldic[noticerepair.Level];
                noticerepair.SbepRealname = await db.Queryable<Employee>().Where(ep => ep.Id == noticerepair.Sbepid).Select(ep => ep.Realname).SingleAsync();
            }
            var result = await exporter.Export(@"wwwroot/download/baoxiu/报修.xlsx", noticerepairs);

            JObject data = new();
            data.Add("url", $"http://{App.HttpContext.Request.Host.Value}/download/baoxiu/报修.xlsx");
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = data,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public async Task<IActionResult> PostImportexcel([FromForm] string filePath)
        {
            //filePath = @"upload/excel/报修模板.xlsx";
            string webrootpath = _env.WebRootPath;
            FileInfo file = new(Path.Combine(webrootpath, filePath));

            long affrows = 0;
            try
            {
                using (ExcelPackage package = new(file))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.First();
                    int rowCount = worksheet.Dimension.Rows;
                    var items = new List<NoticeRepair>();
                    for (int row = 2; row <= rowCount; row++)
                    {
                        items.Add(new NoticeRepair { });
                    }
                    //affrows = await db.Insertable(items).ExecuteCommandAsync();
                }
            }
            catch (Exception e)
            {
                affrows = -1;
                Console.WriteLine("导入报修失败：" + e.Message);
            }

            if (affrows == -1)
            {
                return new JsonResult(new RESTfulResult<object>
                {
                    StatusCode = -1,
                    Succeeded = true,
                    Data = false,
                    Errors = null,
                    Extras = UnifyContext.Take(),
                    Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                });
            }
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = null,
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }
    }
}
